//打开修改密码
function modifyPassword() {
    layui.use(['form','layer'], function(){
        var form = layui.form;
        let layer = layui.layer;
        layer.open({
            type: 1,
            // skin: 'layui-layer-rim', 加边框
            title: "修改密码",
            area: ['450px', '300px'],
            content: '<form class="layui-form" xmlns="http://www.w3.org/1999/html"> \n' +
                '  <div class="layui-form-item" style="padding-top: 10px">\n' +
                '    <label class="layui-form-label">旧密码</label>\n' +
                '    <div class="layui-input-block">\n' +
                '      <input type="password" id="oldpwd" name="oldpwd" placeholder="旧密码" autocomplete="off" class="layui-input" style="width: 300px">\n' +
                '    </div>\n' +
                '  <div class="layui-form-item" style="padding-top: 10px">\n' +
                '    <label class="layui-form-label">新密码</label>\n' +
                '    <div class="layui-input-block">\n' +
                '      <input type="password" id="newpwd" name="newpwd" placeholder="新密码" autocomplete="off" class="layui-input" style="width: 300px">\n' +
                '    </div>\n' +
                '  </div>' +
                '  <div class="layui-form-item">\n' +
                '    <label class="layui-form-label">确认新密码</label>\n' +
                '    <div class="layui-input-block">\n' +
                '      <input type="password" id="oknewpwd" name="oknewpwd" placeholder="确认新密码" autocomplete="off" class="layui-input" style="width: 300px">\n' +
                '    </div>\n' +
                '  </div>' +
                '   <div class="layui-input-block">\n' +
                '<button class="layui-btn"  onclick="modifyOk()" type="button">修改</button></br>\n' +
                '</div>' +
                '</div>' +
                '</form>'
        })
    });
}
//打开邮件发送
function sendNotice() {
    layui.use(['form','layer'], function(){
        var form = layui.form;
        let layer = layui.layer;
        layer.open({
            type: 1,
            // skin: 'layui-layer-rim', 加边框
            title: "发送邮件",
            area: ['450px', '480px'],
            content: '<form class="layui-form" xmlns="http://www.w3.org/1999/html"> \n' +
                '  <div class="layui-form-item" style="padding-top: 10px">\n' +
                '    <label class="layui-form-label">标题</label>\n' +
                '    <div class="layui-input-block">\n' +
                '      <input type="text" id="title" name="title" placeholder="标题" autocomplete="off" class="layui-input" style="width: 300px">\n' +
                '    </div>\n' +
                '  <div class="layui-form-item layui-form-text" style="padding-top: 10px">\n' +
                '    <label class="layui-form-label">内容</label>\n' +
                '    <div class="layui-form-label">\n' +
                '      <textarea placeholder="请输入内容" class="layui-textarea" id="content" name="content" style="width: 300px"></textarea >\n' +
                '    </div>\n' +
                '  </div>' +
                '  <div class="layui-form-item" style="padding-top: 10px">\n' +
                '    <label class="layui-form-label">发送给</label>\n' +
                '    <div class="layui-input-block">\n' +
                '      <input type="text" id="sAge" name="sAge" placeholder="年纪" autocomplete="off" class="layui-input" style="width: 300px">\n' +
                '    </div>\n' +
                '  <div class="layui-form-item" style="padding-top: 10px">\n' +
                ' <label class="layui-form-label">选择年纪单位</label>\n' +
                '    <div class="layui-input-block">\n' +
                '      <input type="radio" name="age" value="岁" title="岁" id="age">\n' +
                '      <input type="radio" name="age" value="月" title="月" id="age" checked>\n' +
                '    </div>'+
                '</div>' +
                '   <div class="layui-input-block">\n' +
                '<button class="layui-btn"  onclick="send()" type="button">发送</button></br>\n' +
                '</div>' +
                '</div>' +
                '</form>',
            success: function(){
                form.render();
            }

        })
    });
}
//修改密码
function modifyOk() {
    let oldpwd = $("#oldpwd").val();
    let newpwd = $("#newpwd").val();
    let oknewpwd = $("#oknewpwd").val();
    let user = sessionStorage.getItem("user");
    let parse = JSON.parse(user);
    layui.use(['form','layer'], function(){
        let form = layui.form;
        let layer = layui.layer;
        if (oldpwd!==parse.uPwd){
            layer.msg("原密码错误")
        } else if(newpwd!==oknewpwd){
            layer.msg("两次密码不一致")
        }else if (newpwd===""||oknewpwd===""){
            layer.msg("修改密码不能为空")
        }else if (newpwd.length<6){
            layer.msg("密码长度不能小于6位")
        }else {
            layer.open({
                title: "修改密码",
                content: '是否修改密码'
                ,btn: ['确定', '取消']
                ,yes: function(index, layero){
                        //按钮【按钮一】的回调
                        $.post("/modifyAdminPwd",{"newPwd":newpwd},function (data) {
                            if (data.code===500){
                                layer.msg(data.msg)
                            }else if (data.code===200){
                                sessionStorage.removeItem("user")
                                window.location.href="index.html"
                            }
                        },"json")
                }
            });
        }
    });
}
//发送邮件
function send() {
    let title = $("#title").val();
    let content = $("#content").val();
    let sAge = $("#sAge").val();
    let val = $("#age").val();
    let age = sAge+val;
    layui.use(['form','layer'], function() {
        var form = layui.form;
        let layer = layui.layer;
        layer.open({
            title: '发送邮件',
            content: '是否发送通知邮件'
            ,btn: ['确定', '取消']
            ,yes: function(index, layero){
                //按钮【按钮一】的回调
                $.post("/sendAdminNotice",{"title":title,"content":content,"age":age},function (data) {
                    layer.msg("邮件正在发送...")
                },"json")
            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调

                //return false 开启该代码可禁止点击该按钮关闭
            }
            ,cancel: function(){
                //右上角关闭回调

                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
    })
}